//
//  HMEmoticonButton.swift
//  Weibo24
//
//  Created by apple on 17/4/8.
//  Copyright © 2017年 itheima. All rights reserved.
//

import UIKit
//  自定义表情按钮
class HMEmoticonButton: UIButton {
    //  关联的表情模型
    var emoticon: HMEmoticon? {
        didSet {
            
            guard let currentEmoticon = emoticon else {
                return
            }
            
            self.isHidden = false
            if currentEmoticon.type == "0" {
                //  从指定bundle加载图片
//                UIImage(named: "", in: nil, compatibleWith: nil)
                //  图片表情
                self.setImage(UIImage(named: currentEmoticon.path!), for: .normal)
                self.setTitle(nil, for: .normal)
            } else {
                //  emoji表情
                let emoji = (currentEmoticon.code! as NSString).emoji()
                self.setTitle(emoji, for: .normal)
                self.setImage(nil, for: .normal)
            }
        }
    }
 
}
